package com.yunji.hushuang.abstractfactory;

import com.yunji.hushuang.control.GUIFactory;
import com.yunji.hushuang.control.mac.MacGUIFactory;
import com.yunji.hushuang.control.win.WinGUIFactory;

/**
 * 强大的工厂模式综合体
 *
 * @author hushuang
 * @since 2019/9/26
 */
public class GUIFactoryTest {


    /**
     * 根据运行环境，创建出对应操作系统的GUI
     */
    public static GUIFactory create(String os) {
        switch (os) {
            case "win":
                return new WinGUIFactory();
            case "mac":
                return new MacGUIFactory();
            default:
                throw new IllegalArgumentException("不支持的操作系统");
        }
    }

    public static void main(String[] args) {
        // 如果操作环境是 windows
        GUIFactory winGUIFactory = create("win");
        winGUIFactory.createButton().paint();
        winGUIFactory.createText().paint();

        // 如果操作环境是 mac
        GUIFactory macGUIFactory = create("mac");
        macGUIFactory.createButton().paint();
        macGUIFactory.createText().paint();
    }
}
